package com.ruoyi.web.controller.house;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.data.MD5;
import com.ruoyi.data.domain.ParameterSingleT;
import com.ruoyi.data.service.IParameterSingleService;
import com.ruoyi.houseInformation.domain.HouseDoorInformation;
import com.ruoyi.houseInformation.service.IHouseDoorInformationService;
import com.ruoyi.util.SysParamKey;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 身份认证Controller
 * 
 * @author lijie
 * @date 2023-07-25
 */
@RestController
@RequestMapping("/house/information")
public class HouseDoorInformationController extends BaseController
{
    @Autowired
    private IHouseDoorInformationService houseDoorInformationService;

    @Autowired
    private IParameterSingleService parameterSingleService;
    /**
     * 查询身份认证列表
     */
 @GetMapping("/list")
    public TableDataInfo list(HouseDoorInformation houseDoorInformation) throws Exception {
        startPage();
        if(houseDoorInformation.getUserName()!=null){
            houseDoorInformation.setUserName(MD5.encrypt(houseDoorInformation.getUserName()));
        }
        if(houseDoorInformation.getPapersCode()!=null){
            houseDoorInformation.setPapersCode(MD5.encrypt(houseDoorInformation.getPapersCode()));
        }
        List<HouseDoorInformation> list = houseDoorInformationService.selectHouseDoorInformationList(houseDoorInformation);
        for(HouseDoorInformation houseDoorInformationVO:list){
            houseDoorInformationVO.setPapersCode(MD5.decrypt(houseDoorInformationVO.getPapersCode()));
            houseDoorInformationVO.setUserName(MD5.decrypt(houseDoorInformationVO.getUserName()));
            houseDoorInformationVO.setTel(MD5.decrypt(houseDoorInformationVO.getTel()));
            houseDoorInformationVO.setFrontidCardHttp(RuoYiConfig.getPhotoHttp() +"\\"+houseDoorInformationVO.getFrontidCardHttp()+".jpg");
            houseDoorInformationVO.setHomeCardHttp(RuoYiConfig.getPhotoHttp()+"\\"+houseDoorInformationVO.getHomeCardHttp()+".jpg");
            houseDoorInformationVO.setVersoidCardHttp(RuoYiConfig.getPhotoHttp()+"\\"+houseDoorInformationVO.getVersoidCardHttp()+".jpg");
        }
        return getDataTable(list);
    }

    @GetMapping(value = "/housePass/{batchIds}")
    public AjaxResult housePass(@PathVariable("batchIds") Long[] batchIds)
    {
        HouseDoorInformation houseDoorInformation = new HouseDoorInformation();
        houseDoorInformation.setInformationSts("1");
        return toAjax(houseDoorInformationService.updateStsById(batchIds, houseDoorInformation));
    }

    @GetMapping(value = "/houseRefuse/{batchIds}")
    public AjaxResult houseRefuse(@PathVariable("batchIds") Long[] batchIds)
    {
        HouseDoorInformation houseDoorInformation = new HouseDoorInformation();
        houseDoorInformation.setInformationSts("2");
        return toAjax(houseDoorInformationService.updateStsById(batchIds, houseDoorInformation));
    }

    /**
     * 导出身份认证列表
     */
    @Log(title = "身份认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseDoorInformation houseDoorInformation) throws Exception {
        List<HouseDoorInformation> list = houseDoorInformationService.selectHouseDoorInformationList(houseDoorInformation);
        for(HouseDoorInformation houseDoorInformationVO:list){
            houseDoorInformationVO.setPapersCode(MD5.decrypt(houseDoorInformationVO.getPapersCode()));
            houseDoorInformationVO.setUserName(MD5.decrypt(houseDoorInformationVO.getUserName()));
            houseDoorInformationVO.setTel(MD5.decrypt(houseDoorInformationVO.getTel()));
        }
        ExcelUtil<HouseDoorInformation> util = new ExcelUtil<HouseDoorInformation>(HouseDoorInformation.class);
        util.exportExcel(response, list, "身份认证数据");
    }

}
